#!/bin/bash
. appenv
. classpath
cd $SERVER/script

start(){
    rm -rf nohup.out
    touch nohup.out
    nohup /usr/java/jdk1.8.0_73/bin/java -Xms128m -Xmx256m -cp ${APPCLASSPATH} -Dflag=${SERVERNAME}  ${MainClass} >nohup.out 2>&1 &
    echo $! > server.pid 
    echo "SERVER --------> [${SERVERNAME}] ALREADY START"
    tail -f nohup.out 
}

stop(){
    kill `cat server.pid`   
    rm -rf server.pid   
    echo "SERVER --------> [${SERVERNAME}] ALREADY STOP"
}


restart(){
    echo "SERVER --------> [${SERVERNAME}] ALREADY RESTRAT"
    stop   
    sleep 1   
    start
}

echo "Please choose Command: {start:1|stop:2|restart:3}"  
read aNum
case $aNum in
    1)  
    start
    ;;
    2)
    stop
    ;;
    3)
    restart
    ;;
    *)  echo 'You do not select a number between 1 to 3'
    ;;
esac
exit 1
